# encoding: utf-8

# leetcode 0633


from math import sqrt


class Solution:
    def judgeSquareSum(self, c: int) -> bool:
        hi = int(sqrt(c))
        lo = 0
        res = 0

        while lo <= hi:
            res = lo * lo + hi * hi
            if res > c:
                hi -= 1
            elif res < c:
                lo += 1
            else:
                return True
        return False
